/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ifconnect.model.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;

/**
 *
 * @author Genemes
 */
@Entity
public class Turma implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @SequenceGenerator(name = "Turma_ID", sequenceName = "Turma_SEQUENCE", allocationSize = 1, initialValue = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "Turma_ID")
    private Long id;
    private String ano;
    private String semestre;
    
    @OneToMany(mappedBy="turma", cascade={CascadeType.ALL}) 
    private Collection<Usuario> usuarios = new ArrayList<Usuario>();
    
    @ManyToOne
    private Curso curso;

    public Turma() {}

    public Turma(String ano, String semestre) {
        this.ano = ano;
        this.semestre = semestre;
    }

    public Turma(String ano, String semestre, Curso curso) {
        this.ano = ano;
        this.semestre = semestre;
        this.curso = curso;
    }

    

    public boolean addUsuario(Usuario usuario){
        return this.usuarios.add(usuario);
    }

    public void removeUsuario(Usuario usuario) {
        this.usuarios.remove(usuario);
    }

    public Curso getCurso() {
        return curso;
    }

    public void setCurso(Curso curso) {
        this.curso = curso;
    }

    public String getAno() {
        return ano;
    }

    public void setAno(String ano) {
        this.ano = ano;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getSemestre() {
        return semestre;
    }

    public void setSemestre(String semestre) {
        this.semestre = semestre;
    }
    
    

    public Collection<Usuario> getUsuarios() {
        return usuarios;
    }

    public void setUsuarios(Collection<Usuario> usuarios) {
        this.usuarios = usuarios;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Turma other = (Turma) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        if (this.ano != other.ano) {
            return false;
        }
        if (this.semestre != other.semestre) {
            return false;
        }
        if (this.usuarios != other.usuarios && (this.usuarios == null || !this.usuarios.equals(other.usuarios))) {
            return false;
        }
        if (this.curso != other.curso && (this.curso == null || !this.curso.equals(other.curso))) {
            return false;
        }
        return true;
    }

    

    @Override
    public String toString() {
        return this.ano + "." +this.semestre+" - "+this.curso.getNome();
    }
}
